package com.owc.service.impl.admin;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.owc.common.tool.BeanUtils;
import com.owc.dao.NoticeMapper;
import com.owc.domain.PageBean;
import com.owc.domain.dto.NoticeDTO;
import com.owc.domain.dto.admin.NoticeInfoDTO;
import com.owc.domain.entity.Notice;
import com.owc.domain.vo.admin.QueryVo;
import com.owc.service.admin.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Author xiaom
 * @Date 2020/3/3 10:29
 * @Version 1.0.0
 * @Description <>
 **/
@Service
@Slf4j
public class NoticeServiceImpl implements NoticeService {

    @Resource
    private NoticeMapper noticeMapper;

    @Override
    public Boolean save(Notice notice) {
        noticeMapper.insert(notice);
        return true;
    }

    @Override
    public PageBean<NoticeInfoDTO> pageList(QueryVo queryVo) {
        PageHelper.startPage(queryVo.getPageIndex(),queryVo.getPageSize());
        List<Notice> notices = noticeMapper.selectByFilter(queryVo);
        PageInfo<Notice> pageInfo = new PageInfo<>(notices);
        return PageBean.pageBean(pageInfo.getTotal(), BeanUtils.coventObject(pageInfo.getList(),NoticeInfoDTO.class));
    }

    @Override
    public Boolean update(Notice notice) {
        noticeMapper.updateByPrimaryKeySelective(notice);
        return true;
    }
}
